

class UserInfo:
    # 用户编号 id_no,姓名 name,登录名 login_name,登录密码 pwd,性别 sex,年龄 age,状态status,备注 remark
    def __init__(self,**kwargs):
        print("------------------初始化 UserInfo-----------")
        self.id_no = kwargs.get("id_no")
        self.name = kwargs.get("name")
        self.login_name = kwargs.get("login_name")
        self.pwd = kwargs.get("pwd")
        self.sex = kwargs.get("sex")
        self.age = kwargs.get("age")
        self.status = kwargs.get("status")
        self.remark = kwargs.get("remark")


    """
    用户登录操作：
    1.获取用户名和密码
    2.验证用户名和密码   
    3.返回登录结果 True-成功：False-失败
    """
    def login(self,login_name,pwd):
        # 登录
        with open("user_list.csv", "r", encoding="utf-8") as f:
            for line in f.readlines():
                user = line.strip().split(",")
                print("打印出用户信息：",user)

                if user[2]==login_name and user[3]==pwd:
                    return True
        return False

    """从文件中查询用户信息,通过登录名查询"""
    @staticmethod
    def query_by_loginname(login_name):
        # 登录
        with open("user_list.csv", "r", encoding="utf-8") as f:
            for line in f.readlines():
                user = line.strip().split(",")

                print("打印出用户信息：",user)
                if user[2]==login_name:
                    # 转换对象
                    user = UserInfo(
                        **dict(zip(["id_no", "name", "login_name", "pwd", "sex", "age", "status", "remark"], user)))
                    return user
        return None